package cn.com.thinvent.dispatch.web.controller;

import cn.com.thinvent.dispatch.entity.ActivityManagement;
import cn.com.thinvent.dispatch.entity.response.PagedGridResult;
import cn.com.thinvent.dispatch.entity.response.ReturnModel;
import cn.com.thinvent.dispatch.service.biz.ActivityManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/activity")
public class ActivityManagementController {

    @Autowired
    private ActivityManagementService activityManagementService;

    @PostMapping("/add")
    public ReturnModel addActivity(@RequestBody ActivityManagement activityManagement) {
        activityManagementService.addActivity(activityManagement);
        return new ReturnModel(200, null,"Activity added successfully");
    }

    @PutMapping("/update")
    public ReturnModel updateActivity(@RequestBody ActivityManagement activityManagement) {
        activityManagementService.updateActivity(activityManagement);
        return new ReturnModel(200, null,"Activity updated successfully");
    }

    @DeleteMapping("/delete/{id}")
    public ReturnModel deleteActivity(@PathVariable String id) {
        activityManagementService.deleteActivityById(id);
        return new ReturnModel(200, null, "Activity deleted successfully");
    }

    @GetMapping("/get/{id}")
    public ReturnModel getActivityById(@PathVariable String id) {
        ActivityManagement activity = activityManagementService.getActivityById(id);
        return new ReturnModel(200, activity,"Success");
    }

    @GetMapping("/list")
    public ReturnModel getActivityList(@RequestParam(defaultValue = "1") int pageNum,
                                       @RequestParam(defaultValue = "10") int pageSize,
                                       @RequestParam String activityType,
                                       @RequestParam Date startTime,
                                       @RequestParam Date endTime) {

        PagedGridResult<ActivityManagement> activityList = activityManagementService.getActivityList
                (pageNum, pageSize, activityType, startTime, endTime);
        return new ReturnModel(200, activityList,"Success");
    }
}
